<template>
	<view>
		<view class="titles-bar">
			<title-bar :titleList="titleList" @getValue="changeTitle"></title-bar>
			<view class="time-manage" @click="changTime()">
				<image style="width: 100%;height: 100%;" :src="icons.timeManage"></image>
			</view>
		</view>
		<view class="table-head">
			<view v-for="(item, index) in headList" :key="index" class="head-item">
				{{ item.name }}
			</view>
		</view>
		<view class="table-content">
			<view v-for="(item, index) in contentList" :key="index" class="content-list">
				<view class="content-item">
					{{ item.time }}
				</view>
				<view class="content-item">
					{{ item.name }}
				</view>
				<view class="content-item">
					{{ item.number }}
				</view>
				<view class="content-item">
					{{ item.man }}
				</view>
			</view>
		</view>
		<uni-popup ref="timePopup" type="bottom">
			<view class="leave_cont">
				<view class="time-header">
					<view class="time-items time-cancel" @click="timeSelect(1)">取消</view>
					<view class="time-items time-confirm" @click="timeSelect(2)">确定</view>
				</view>
				<view class="ul">
					<view class="li">
						<text>开始时间</text>
						<view class="flex1">
							<picker mode="date" :value="start_date" :start="start_date" :end="other" @change="bindDateChange">
								<view class="date">{{start_date}}</view>
							</picker>
						</view>
					</view>
					<view class="li">
						<text>结束时间</text>
						<view class="flex1">
							<picker mode="date" :value="start_date" :start="start_date" @change="bindDateChange2">
								<view class="date">{{other}}</view>
							</picker>
						</view>
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import titleBar from '@/components/title-bar/index.vue';
	import uniPopup from '@/components/uni-popup/uni-popup.vue';

	export default {
		components: {
			titleBar,
			uniPopup
		},
		data() {
			const currentDate = this.getDate({
				format: true
			})
			return {
				start_date: currentDate,
				end_date: currentDate,
				other: '请输入',
				titleList: [{
					name: '补货记录'
				}, {
					name: '回收记录'
				}],
				icons: {
					timeManage: '/static/images/icon_sj@3x.png'
				},
				headList: [{
					name: '时间'
				}, {
					name: '品名'
				}, {
					name: '数量'
				}, {
					name: '操作人'
				}],
				contentList: [{
					name: '鸡腿套餐',
					number: 10,
					man: '操作人',
					time: '02-06  11:00'
				}, {
					name: '鸡腿套餐',
					number: 10,
					man: '操作人',
					time: '02-06  11:00'
				}, {
					name: '鸡腿套餐',
					number: 10,
					man: '操作人',
					time: '02-06  11:00'
				}, {
					name: '鸡腿套餐',
					number: 10,
					man: '操作人',
					time: '02-06  11:00'
				}]
			}
		},
		methods: {
			changeTitle(index) {
				console.log('index111', index)
			},
			// 选择日期
			bindDateChange: function(e) {
				this.start_date = e.target.value

			},
			bindDateChange2: function(e) {
				this.end_date = e.target.value;
				this.other = this.end_date;
			},
			// 获取当前时间
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();

				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			},
			changTime() {
				console.log('改变时间')
				this.$refs.timePopup.open();
			},
			timeSelect(statu) {
				console.log('statu', statu)
				this.$refs.timePopup.close();
			}
		}
	}
</script>

<style>
	.titles-bar {
		width: 100%;
		height: 122rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0 26rpx 0 30rpx;
		box-sizing: border-box;
	}

	.time-manage {
		width: 70rpx;
		height: 70rpx;
		padding-top: 8rpx;
		box-sizing: border-box;
	}

	.table-head {
		height: 82rpx;
		display: flex;
		align-items: center;
		background-color: #F5F5F5;
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: rgba(153, 153, 153, 1);
		padding: 0 30rpx;
	}

	.head-item {
		flex: 1;
	}

	.content-list {
		height: 82rpx;
		display: flex;
		align-items: center;
		padding: 0 30rpx;
		border-bottom: 1rpx solid #E0E0E0;
	}

	.content-item {
		flex: 1;
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: rgba(51, 51, 51, 1);
	}

	.leave_cont {
		background-color: #ffffff;
	}

	.leave_cont .ul {
		padding: 0 30rpx;
	}

	.leave_cont .ul .li {
		display: flex;
		align-items: center;

	}

	.leave_cont .ul .li:not(:last-child) {
		border-bottom: 1rpx solid #efefef;
	}

	.leave_cont .ul .li text {
		padding: 40rpx 0;
		font-size: 34rpx;
		font-family: '黑体';
	}

	.leave_cont .ul .li .flex1 {
		flex: 1;
		text-align: right;
		padding-right: 25rpx;
		color: #999999;
		font-size: 32rpx;
	}

	.time-header {
		display: flex;
		justify-content: space-between;
		border-bottom: 1rpx solid #e5e5e5;
		height: 98rpx;
		align-items: center;
	}

	.time-items {
		padding: 0rpx 28rpx;
		font-size: 36rpx;
	}

	.time-cancel {
		color: #888;
	}

	.time-confirm {
		color: #007aff;
	}
</style>
